package 笔记.设计模式.抽象工厂模式;

/**
 * @author chenhailong
 * @ClassName: Text
 * @Description: 测试工厂
 * @date 2021/6/29 20:28
 * @Version 1.0
 */
public class Text {

    public static void main(String[] args) {

        /**
         * 抽象工厂模式：
         *      主要功能的在工厂的基础上再抽象，把工厂也模具化，批量新建模具工厂，再批量新建模具类，不同的工厂对应不同的模具类
         */
        // 直接分类工厂获取
        AnimalFactroy animalFactroy = new AnimalFactroy();
        Animal animalone = animalFactroy.getAnimal("animalone");
        Animal animaltwo = animalFactroy.getAnimal("animaltwo");
        animalone.eat();
        animaltwo.eat();
        PlantFactory plantFactory = new PlantFactory();
        Plant plantone = plantFactory.getPlant("plantone");
        Plant planttwo = plantFactory.getPlant("planttwo");
        plantone.root();
        planttwo.root();

        // 获取分类工厂，再获取类
        FactoryAbstract animalfactory = FactoryProducer.getFactory("animalfactory");
        Animal animalone1 = animalfactory.getAnimal("animalone");
        animalone1.eat();

        FactoryAbstract plantfactory = FactoryProducer.getFactory("plantfactory");
        Plant plantone1 = plantfactory.getPlant("plantone");
        plantone1.root();


    }

}
